/*
 * Achieve it All! - Android app to motivate achieving your goals
 * Copyright (C) 2014  Xilconic
 * 
 * This file is part of Achieve it All!.
 *
 * Achieve it All! is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Achieve it All! is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Achieve it All!.  If not, see <http://www.gnu.org/licenses/>
 */
package com.xilconic.achieveitall.domain;

import android.os.Parcel;
import android.os.Parcelable;

public class Target implements Parcelable{
	private String name;
	private String description;
	private boolean isFinished;
	private int pointsReward;
	private long id;
	
	public Target(){
		name = "";
		description = "";
		id = -1;
	}
	
	/**
	 * Constructs an instance of {@link Target} from a {@link Parcel}.
	 * @param in Parcel to recreate from.
	 */
	public Target(Parcel in) {
	    id = in.readLong();
		name = in.readString();
		description = in.readString();
		pointsReward = in.readInt();
		boolean[] classBooleans = new boolean[1];
		in.readBooleanArray(classBooleans);
		isFinished = classBooleans[0];
	}

	/**
	 * Returns the given name of this achievement target.
	 * @return The name of the achievement target.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Set a new name for this achievement target.
	 * @param newName The new name.
	 */
	public void setName(String newName) {
		name = newName;
	}

	/**
	 * Returns the given descriptive text or explanations of this achievement
	 * target.
	 * @return The description.
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Sets the descriptive text of explanations of this achievement target.
	 * @param newDescription The new description.
	 */
	public void setDescription(String newDescription) {
		description = newDescription;		
	}

	/**
	 * Indicates if this achievement target has been met or not.
	 * @return True if the achievement target has been met, false otherwise.
	 */
	public boolean isFinished() {
		return isFinished;
	}

	/**
	 * Updates the finished status of this achievement target.
	 * @param newFinishedState The new state.
	 */
	public void setFinished(boolean newFinishedState) {
		isFinished = newFinishedState;	
	}

	/**
	 * Returns the amount of achievement points awarded for finishing this
	 * achievement target.
	 * @return The achievement points reward.
	 */
	public int getPointsReward() {
		return pointsReward;
	}

	/**
	 * Set an achievement points reward for finishing this achievement target.
	 * @param newPointsReward The new points reward.
	 */
	public void setPointsReward(int newPointsReward) {
		pointsReward = newPointsReward;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
	    dest.writeLong(id);
		dest.writeString(name);
		dest.writeString(description);
		dest.writeInt(pointsReward);
		boolean[] classBooleans = new boolean[]{isFinished};
		dest.writeBooleanArray(classBooleans);
	}

	/**
	 * Object creator to create a {@link Target} from {@link Parcel}
	 * contents.
	 */
    public static final Parcelable.Creator<Target> CREATOR
	    = new Parcelable.Creator<Target>() {
		public Target createFromParcel(Parcel in) {
		    return new Target(in);
		}
		
		public Target[] newArray(int size) {
		    return new Target[size];
		}
    };

    /**
     * The SQLite database ID value.
     * @return The SQLite database ID, or -1 if not persisted yet.
     */
    public long getId() {
        return id;
    }
    
    /**
     * Sets a new SQLite database ID value.
     * @param newId The new ID.
     */
    public void setId(long newId){
        id = newId;
    }
}
